package com.wzdigit.wms.wms.service.core.transfer;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.transfer.DocPreAloc;
import com.wzdigit.wms.basic.mapper.core.transfer.DocPreAlocMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
@Slf4j
public class DocPreAlocService {

	@Autowired
	DocPreAlocMapper docPreAlocMapper;


	/**
	 * 根据发货单明细ID查询预配表
	 * @param gdnIdList
	 * @return
	 */
	public List<DocPreAloc> selectByDocDtlIdList(List<Long> gdnIdList) {

		//创建类型的条件构造器
		QueryWrapper<DocPreAloc> wrapper = new QueryWrapper<>();
		wrapper.in("DOC_DTL_ID", gdnIdList);

		List<DocPreAloc> docPreAlocList = docPreAlocMapper.selectList(wrapper);
		return docPreAlocList;
	}

	/**
	 * 根据明细ID获取预配表
	 * @param docDtlId
	 * @return
	 */
	public DocPreAloc selectByDocDtlId(Integer docDtlId) {

		//创建类型的条件构造器
		QueryWrapper<DocPreAloc> wrapper = new QueryWrapper<>();
		wrapper.eq("DOC_DTL_ID", docDtlId);

		DocPreAloc docPreAloc = docPreAlocMapper.selectOne(wrapper);
		return docPreAloc;
	}

	/**
	 * 根据主键查询
	 * @param docPreAlocId
	 * @return
	 */
	public DocPreAloc selectByPk(Integer docPreAlocId) {

		DocPreAloc docPreAloc = docPreAlocMapper.selectById(docPreAlocId);
		return docPreAloc;
	}

	public Integer addNewOne(DocPreAloc docPreAloc) {
		int row = docPreAlocMapper.insert(docPreAloc);
		return row;
	}

	public Integer updateSplit(DocPreAloc docPreAloc, BigDecimal splitQty) {

		int row = docPreAlocMapper.updateSplit(docPreAloc, splitQty);
		return row;
	}
}